package com.example.service;

import com.example.entity.Post;
import com.example.entity.PostCategory;
import com.example.mapper.PostMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/*
帖子业务处理
 */
@Service
public class PostService {

    @Resource
    private PostMapper postMapper;

    public void add(Post post) {
        postMapper.insert(post);
    }

    public void deleteById(Integer id) {
        postMapper.deleteById(id);
    }

    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids){
            this.deleteById(id);
        }
    }

    public void updateById(Post post) {
        postMapper.updateById(post);
    }

    public Post selectById(Integer id) {
        return postMapper.selectById(id);
    }

    public List<Post> selectAll(Post post) {
        return postMapper.selectAll(post);
    }

    public PageInfo<Post> selectPage(Post post, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Post> postList = postMapper.selectAll(post);
        return PageInfo.of(postList);
    }
}
